package com.platform.common.config;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Configuration
@ConfigurationProperties(prefix = "wxpay")
public class WxPayConfig {
    /** 加载证书  这里证书需要到微信商户平台进行下载*/
    public static String privateKeyForDecrypt="-----BEGIN PRIVATE KEY-----\n" +
            "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDN6DUEtqlml1PN\n" +
            "LT5kQFfbr8UTDCAyjHK3N3w2AjACTcvoKoHYItz4+GeUk1jdOvk7GyssWXMtElkC\n" +
            "16T9REKQMu4yExYGRUV8kjkq/4gToRDNwpv7BxltnyQTW2LLIGkN2PHUUtqMDLOO\n" +
            "Oca97757DkHbUOXpVjwvU0F83BQ0akxznNp0swr+YgB4VAAsloLmJ6sKWcNBbP2o\n" +
            "fQLB4gOn7N7zdD5mLxIPkg7QE6K6ZDL75sjkmbdQm+tI0ri9JsJFEohDY6fUxjXc\n" +
            "mYH2Lur93CBH8FmOHQn7xlZZqEi2qH9tQPjnDstUREe0BNDHICYdxFYJZ+tFRGYF\n" +
            "83rqswqbAgMBAAECggEAKDWWVOtOvWgDx2d0baNbBN2YQJX3m6dtp3XAXdOjiG+k\n" +
            "yBu0634zZLMtlwgHLHyduvsdPTXilgSlOTbfU04HKZ2ogkLT5DmWzjLH0yu/aQXl\n" +
            "AClmyGikgJG5O8Z2zm/v0/JvlyTu5LZ+QeHqe6Dbs7AfEDMGEsDyU9OQUE+x6mIW\n" +
            "A5O9CO4rv90fo49M1xJNC50OrHNCETDCIseIW56J+6CJsE64TODSAZJEdBb9VIB1\n" +
            "GrXq0EDo1UhdJ9smIUqKlvn6CGCg4NX/iP905V+cDD/qbNb+X87Tp9yxYIDYcwsQ\n" +
            "v4bYLomyqi78cHXCxd4koJE98tmMqJ8tW9WjB2BWsQKBgQDsBohIDGnv94f209S4\n" +
            "9xXkP5L08V5BpahUnaBUBu6ieig4OyLjxrqOAO7QkaQDSxNnVtMkzryHdb6b6PDi\n" +
            "Fz7OiIlyePmma5dfE+NIuyrmx9wL4/EOU9vYQtSYbxcyVaBKg5dmTe4WtuwMBm2d\n" +
            "z726vlKSW2bCQhOj3dEWzqlOtwKBgQDfVSlc59dk6ujuEIkIHJiASaTyt4dRWhn3\n" +
            "lX2GYYTPbsSVvYzpQNFkhkA6J/ayDEOuarooEAdU79gFPRIWFtSNK4qgC5IvyfDI\n" +
            "KW1VlA860oFoB1B7dYUYdveO2FHHSfVJtEMfWj2GplphiPscK5MEYe1p0uZ8Yc77\n" +
            "yRl+DaX/PQKBgQC+9DICCHkU+jD4Uz2BP/ZoKb8diMH3Xq0neDekg89BiI9NnxqF\n" +
            "Kdz40mxkNdB6EZ1rN+Wvm8sP1QUXYoiwgpn/wpthD9r694UKGS8DQtpcyEmRHSOD\n" +
            "sfjlqHwTr50WzgvW/UvaKyZ7HhcvS2wYB2C62ww2+NfURl1ZcDafuydjVQKBgG3b\n" +
            "yIMJEK112Kryu1WgK2w/zcIPgaME/W0KvjqSUfBv/ofiPCSpW9dlKsbwzat72Pc9\n" +
            "TOFUMScY7Fx3VCRFirz+xCxCROD5J1Zu+nd0Y6F912ZC4tY4UwZbzx8XTfMIcH6X\n" +
            "C8WqcEWCI0eDSHLtBF7NhSnfMr3Qpy64F7AoKpXJAoGAbwdbxzpDXTekdOn7Z8V2\n" +
            "YvTNTLLxD3wbmegITNXGQOukd1bUINiZQH6inRUzmyae2YYLCh/1uobQN2oHtSB7\n" +
            "jGKAscA1HlkBzniP1ow597oJOvI9tzBkbJWNz5xk4+5BFtJa+uM5bBEBYcdghMzo\n" +
            "YKZKGSQ865sxXiIZ/pisG0A=\n" +
            "-----END PRIVATE KEY-----";
    // 微信支付参数配置 //
    @Value("${wxpay.appid}")
    public static String appid = "wxa838328d6a53ddd6";//公众账号ID
    @Value("${wxpay.mchid}")
    public static String mchid = "1573954551";//微信支付商户号
    @Value("${wxpay.key}")
    public static String key = "cdf215dad121asdfsdsadq5wcsfgsDAD";//API密钥
    @Value("${wxpay.appsecret}")
    public static String appsecret = "ef500bb944dd2d1af4c85b0a27d07456";//AppSecret是APPID对应的接口密码
    @Value("${wxpay.mchSerialNo}")
    public static String mchSerialNo = "7B7D3FEFD602BD69DE92A98A603F400C8CA38403";
    @Value("${wxpay.apiV3Key}")
    public static String apiV3Key = "xiaoshudingv38888888888888888888";
    @Value("${wxpay.notify_url}")
    public static String notify_url = "https://ocrapi.shudingkj.com/wxpay/notify";//回调地址。测试回调必须保证外网能访问到此地址
    @Value("${wxpay.create_ip}")
    public static String create_ip = "121.41.116.2";//发起请求的电脑IP
    private static CloseableHttpClient httpClient;

    public static String getCertify() {
        String rtn = "";
        try {
            URIBuilder uriBuilder = new URIBuilder("https://api.mch.weixin.qq.com/v3/certificates");
            HttpGet httpGet = new HttpGet(uriBuilder.build());
            httpGet.addHeader("Accept", "application/json");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            rtn = EntityUtils.toString(response.getEntity());
        }catch (Exception e) {}
        return rtn;
    }
}
